import { Inject, Injectable } from '@nestjs/common';
import { createTransport, Transporter } from 'nodemailer';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class EmailService {
    transporter: Transporter
    constructor(private configService: ConfigService) {
        this.transporter = createTransport({
            ...this.configService.get("nodemailer"),
            secure: false,
        });
    }

    async sendMail({ to, subject, html }) {
        await this.transporter.sendMail({
            from: {
                name: '聊天室',
                address: this.configService.get("nodemailer.auth.user")
            },
            to,
            subject,
            html
        })
    }
}
